package com.standard.py.springbootwebservicedemo.service.impl;

import com.alibaba.fastjson.JSON;
import com.standard.py.springbootwebservicedemo.dao.WebserviceMapper;
import com.standard.py.springbootwebservicedemo.service.MPersonService;
import com.standard.py.springbootwebservicedemo.service.WebTestService;
import com.standard.py.springbootwebservicedemo.vo.ResponseVo;
import com.standard.py.springbootwebservicedemo.vo.res.RoomMemberResVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import javax.jws.WebService;
import javax.xml.ws.BindingType;
import javax.xml.ws.soap.SOAPBinding;
import java.util.List;

/**
 * TO DO
 *
 * @author tangjing
 * @date 2021/11/30 10:51
 */
@BindingType(SOAPBinding.SOAP12HTTP_BINDING)
@WebService(name = "test", targetNamespace = "http://service.test.standard.com/",
        endpointInterface = "com.standard.py.springbootwebservicedemo.service.MPersonService", portName = "10000")
@Component
@Slf4j
public class MPersonServiceImpl implements MPersonService {

    @Resource
    private WebserviceMapper webserviceMapper;

    @Resource
    private WebTestService webService;

    @Override
    public ResponseVo<String> selectByPrimaryKey(String testId) {
        log.info("自己完成的业务逻辑：");
        List<RoomMemberResVO> temp = webserviceMapper.getRoomMemberList(Integer.parseInt(testId));
        String result = JSON.toJSONString(temp);
        log.info(result);
        return ResponseVo.content(result);
    }

    @Override
    public String selectTwo(String testId) {
        return "测试查询：" + testId;
    }

    @Override
    public ResponseVo<RoomMemberResVO> selectByPrimaryKey2(String testId) {
        log.info("调用其他的业务逻辑：");
        List<RoomMemberResVO> temp = webService.listMember(Integer.parseInt(testId));
        RoomMemberResVO resVO = CollectionUtils.isEmpty(temp) ? null : temp.get(0);
        return ResponseVo.content(resVO);
    }
}
